﻿/*!	r_util_str.h
	@brief	文字列系ユーティリティ
Copyright (c) 2010 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _R_UTIL_STR_H_
#define _R_UTIL_STR_H_

#include "../r_type.h"

//! 文字列比較
/*! この関数は文字列が一致したときにtrueを返すので注意
*/
template<class T>
r_bool	r_tm_strcmp ( const T* f, const T* s )
{
	for ( r_ui32 i = 0; f[i] == s[i]; ++i ) {
		if ( f[i] == static_cast<T> ( '\0' ) ) {
			return true;
		}
	}
	return false;
}

template<class T>
r_size	r_tm_strlen ( const T* str )
{
	r_size len;
	for ( len = 0; str[len] != static_cast<T> ( '\0' ); ++len );
	return len;
}

#if R_TARGET_COMMONIS(R_TARGET_COMMON_WIN32) || R_TARGET_COMMONIS(R_TARGET_COMMON_WIN64)
#include<windows.h>
//! 文字列を1バイト文字の文字列に変換する
/*!
*/
void	fRStrWideToMulti ( r_mstr	dst, const r_wstr src, r_size length );

void	fRStrMultiToWide ( r_wstr dst, const r_mstr src, r_size length );

//! 文字列のコピー
void	fRStrNCopy ( r_wstr dst, const r_wstr src, r_size buffsize, r_size length );

void	fRStrNCopy ( r_mstr dst, const r_mstr src, r_size buffsize, r_size length );

#endif

void	fRStrCopyToWide ( r_wstr dst, const r_mstr src, r_size buffsize, r_size length );
void	fRStrCopyToWide ( r_wstr dst, const r_wstr src, r_size buffsize, r_size length );
void	fRStrCopyToMulti ( r_mstr dst, const r_mstr src, r_size buffsize, r_size length );
void	fRStrCopyToMulti ( r_mstr dst, const r_wstr src, r_size buffsize, r_size length );

//! sprintf
/*!
@param	dst		[out]	出力バッファ
@param	buffLen	[in]	出力バッファ文字列長
@param	foramt	[in]	入力書式文字列
@param	...		[in]	入力データ
*/
r_si32	fRSprintf ( r_mstr dst, r_size buffLen, const r_mstr format, ... );
r_si32	fRSprintf ( r_wstr dst, r_size buffLen, const r_wstr format, ... );

#endif // _R_UTIL_STR_H_
